<template>
	<view class="searchSelect" v-if='loading'>
		<zxz-uni-data-select v-model="selectId" :filterable='!isDisabled' :localdata="list" :placeholder="placeholder"
			@change="confirm" :clear="true" :disabled='isDisabled'></zxz-uni-data-select>


	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		getInstitutionSearch,
		getDaizhuanAllIntitutions,
		getAllSigns,
		getInstitutions
	} from '@/api/platform/institutions.js'
	import {
		getDicts
	} from '@/api/platform/dicts.js'
	import {
		getOrgansList
	} from '@/api/platform/organs.js'
	export default {
		name: "searchSelect",
		props: {
			isClear: {
				type: Boolean,
				default: true
			},
			isDisabled: {
				type: Boolean,
				default: false
			},
			placeholder: {
				type: String,
				default: '请选择'
			},
			currentCode: { //从那个组件中(doctorExpress:快递管理)传递过来
				type: String,
				default: ''
			},
			searchApi: { //传递的api从而进行调取那个api接口
				type: String,
				default: ''
			},
			selectValue: { //传递的值
				type: [String, Number],
				default: ''
			},
			noticeType: { 
				type: [String, Number],
				default: ''
			},

		},
		computed: {
			...mapState({
				currentinstitutionId: state => state.user.institution.id,
			})
		},
		data() {
			return {
				loading: true,
				selectId: '',
				range: [{
						"value": 0,
						"text": "篮球",
						"disable": true
					},
					{
						"value": 1,
						"text": "足球"
					},
					{
						"value": 2,
						"text": "游泳"
					}
				],
				list: [],
			};
		},
		mounted() {
			if (this.selectValue || this.selectValue === 0) {
				this.selectId = this.selectValue
			}
			if (this.currentCode == 'expressList' && this.searchApi == 'getInstitutionSearch') { //快递管理
				this.getInstitutionList()
			} else if (this.currentCode == 'expressList' && this.searchApi == 'receiveStatus') {
				this.getReceiveStatusList()
			} else if (this.currentCode == 'extraProject' && this.searchApi == 'extraProjectStatus') {
				this.getExtraProjectStatusList()
			} else if (this.currentCode == 'extraProject' && this.searchApi == 'resultEntryStatus') {
				this.getResultEntryStatusList()
			} else if (this.currentCode == 'extraProject' && this.searchApi == 'getInstitutionSearch') {
				this.getInstitutionList()
			} else if (this.currentCode == 'detectionList' && this.searchApi == 'resultEntryStatus') {
				this.getResultEntryStatusList()
			} else if (this.currentCode == 'detectionList' && this.searchApi == 'getInstitutionSearch') {
				this.getInstitutionList()
			} else if (this.currentCode == 'transferInfo' && this.searchApi == 'getDaizhuanAllIntitutions') {
				this.getDaizhuanAllIntitutions()
			} else if (this.currentCode == 'transferInfo' && this.searchApi == 'dataUploadStatus') {
				this.getDataUploadStatusList()
			} else if (this.currentCode == 'pagesGuide' && this.searchApi == 'articleType') {
				this.getArticleTypeList()
			} else if (this.currentCode == 'pagesGuide' && this.searchApi == 'articleTypeRequest') {
				this.articleTypeRequest()
			} else if (this.currentCode == 'pagesGuide' && this.searchApi == 'subspecialtyRequest') {
				this.subspecialtyRequest()
			} else if (this.currentCode == 'pagesGuide' && this.searchApi == 'articleDisplayLocationRequest') {
				this.articleDisplayLocationRequest()
			} else if (this.currentCode == 'consultationApplyList' && this.searchApi == 'orderType') {
				this.getOrderTypeList()
			} else if (this.currentCode == 'consultationApplyList' && this.searchApi == 'getSexList') {
				this.getSexList()
			} else if (this.currentCode == 'customerList' && this.searchApi == 'orderType') {
				this.getOrderTypeList()
			} else if (this.currentCode == 'customerList' && this.searchApi == 'getSexList') {
				this.getSexList()
			} else if (this.currentCode == 'sendInfosNoticeCom' && this.searchApi == 'sendInfosReason') {
				this.getSendInfosReasonList()
			} else if (this.currentCode == 'askList' && this.searchApi == 'getSexList') {
				this.getSexList()
			} else if (this.currentCode == 'askList' && this.searchApi == 'serviceStatus') {
				this.getServiceStatusList()
			} else if (this.currentCode == 'institutionApply' && this.searchApi == 'serviceCenterId') {
				this.getContractHospitalList()
			} else if (this.currentCode == 'institutionApply' && this.searchApi == 'typeOfConsultation') {
				this.getConsultations()
			} else if (this.currentCode == 'institutionApply' && this.searchApi == 'viscera') {
				this.getOrgansList()
			} else if (this.currentCode == 'institutionApply' && this.searchApi == 'specimenCategory') {
				this.getSpecimenCategoryList()
			} else if (this.currentCode == 'institutionApply' && this.searchApi == 'freezeReservation') {
				this.getFreezeReservation()
			} else if (this.currentCode == 'institutionApply' && this.searchApi == 'getSexList') {
				this.getSexList()
			} else if (this.currentCode == 'institutionApply' && this.searchApi == 'maritalStatus') {
				this.getMaritalStatusList()
			} else if (this.currentCode == 'pagesExpert' && this.searchApi == 'institutions') {
				this.getInstitutionsList()
			} else if (this.currentCode == 'pagesExpert' && this.searchApi == 'PathologicalClass') {
				this.getPathologicalClassList()
			} else if (this.currentCode == 'pagesExpert' && this.searchApi == 'TitleForClinic') {
				this.getTitleForClinicList()
			}

		},
		methods: {
			confirm(e) { //确认执行筛选
				let data = e
				// console.log('e---', e)
				// console.log('e---selectId', this.selectId)
				this.$emit('refreshData', data)
			},
			getArticleTypeList() {
				this.list = [{
						text: '文本',
						value: 0
					},
					{
						text: '视频',
						value: 1
					},
				]
			},
			getDataUploadStatusList() {
				this.list = [{
						text: '未上传',
						value: 0
					},
					{
						text: '已上传',
						value: 1
					},
				]
			},
			getResultEntryStatusList() {
				this.list = [{
						text: '已录入',
						value: 3
					},
					{
						text: '部分录入',
						value: 2
					},
					{
						text: '未录入',
						value: 1
					},
				]
			},
			getExtraProjectStatusList() {
				this.list = [{
						text: '已支付',
						value: 3
					},
					{
						text: '部分支付',
						value: 2
					},
					{
						text: '未支付',
						value: 1
					},
				]
			},
			getReceiveStatusList() {
				this.list = [{
						value: 1,
						text: '已签收'
					},
					{
						value: 2,
						text: '未签收'
					},
					{
						value: 5,
						text: '待回寄'
					},
					{
						value: 3,
						text: '已回寄'
					},
					{
						value: 4,
						text: '已退回'
					}
				]
			},
			getOrderTypeList() {
				this.list = [{
						value: 1,
						text: '机构申请'
					},
					{
						value: 2,
						text: '个人申请'
					}
				]
			},
			getServiceStatusList() {
				this.list = [{
						value: 0,
						text: '申请(已整理)'
					},
					{
						value: 1,
						text: '诊断中'
					},
					{
						value: 2,
						text: '诊断结束'
					},
					{
						value: 3,
						text: '退回'
					},
					{
						value: 4,
						text: '调度员退回'
					},
					{
						value: 5,
						text: '申请(未整理)'
					},
					{
						value: 6,
						text: '加做诊断中'
					}
				]
			},
			getMaritalStatusList(){
				this.list = [{
						value: 1,
						text: '未婚'
					},
					{
						value: 2,
						text: '已婚'
					}
				]
			},
			getContractHospitalList() {
				getAllSigns().then(res => {
					if (res.code === 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.serviceInstitutionName,
								value: ele.serviceInstitutionId
							}
							this.list.push(obj)
						})
						console.log('this.list', this.list)
						if (this.list && this.list.length == 1) {
							this.selectId = this.list[0].value
							this.confirm(this.list[0])
							// this.getRegisterPayConfig()
						}
					}
				})
			},
			getConsultations() {
				let data = {
					code: "consultationType"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.id,
								disable: (ele.name === '机构常规' || ele.name === '机构冰冻') ? false : true
							}
							this.list.push(obj)
						})
					}
				})

			},
			getInstitutionsList(){
				getInstitutions().then(res => {
					if (res.code === 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.id
							}
							this.list.push(obj)
						})
				
					}
				})
			},
			getOrgansList() {
				getOrgansList().then(res => {
					if (res.code === 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.id
							}
							this.list.push(obj)
						})

					}
				})
			},
			getSpecimenCategoryList() {
				let data = {
					page: 0,
					size: 99,
					code: "specimenCategory"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.id
							}
							this.list.push(obj)
						})
						if (this.list.length > 0) {
							this.selectId = this.list[0].value
							this.confirm(this.list[0])
						}
					}
				})
			},
			getFreezeReservation(){
				let data = {
					page: 0,
					size: 99,
					code: "freezeReservation"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.id
							}
							this.list.push(obj)
						})
					}
				})
			},
			getSendInfosReasonList() {
				let data = {
					page: 0,
					size: 99,
					code: "sendInfosReason"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.name
							}
							this.list.push(obj)
						})
						if (this.noticeType) {
							let result = this.list.find(e => e.text.indexOf(this.noticeType) > -1)
							this.selectId = result.value
							this.confirm(result)
						} 
					}
				})
			},
			getPathologicalClassList(){
				let data = {
					page: 0,
					size: 999,
					code: "PathologicalClass"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.id
							}
							this.list.push(obj)
						})
					}
				})
			},
			getTitleForClinicList(){
				let data = {
					page: 0,
					size: 999,
					code: "TitleForClinic"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.id
							}
							this.list.push(obj)
						})
					}
				})
			},
			getSexList() {
				let data = {
					page: 0,
					size: 999,
					code: "SexKind"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.id
							}
							this.list.push(obj)
						})
					}
				})
			},
			articleDisplayLocationRequest() {
				let data = {
					page: 0,
					size: 999,
					code: "PathologicalPosition"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							if (ele.name.indexOf('页面') > -1) {
								ele.name = ele.name.replace('页面', '')
							}
							let obj = {
								text: ele.name,
								value: ele.outCode
							}
							this.list.push(obj)
						})
					}
				})
			},
			articleTypeRequest() {
				let data = {
					page: 0,
					size: 999,
					code: "articleType"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.name
							}
							this.list.push(obj)
						})
					}
				})
			},
			subspecialtyRequest() {
				let data = {
					page: 0,
					size: 999,
					code: "subspecialty"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.id
							}
							this.list.push(obj)
						})
					}
				})
			},
			getInstitutionList() {
				let data = {
					page: 0,
					size: 999
				}
				getInstitutionSearch(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						if (this.currentinstitutionId && this.currentinstitutionId != 1) {
							data.forEach(ele => {
								if (ele.id == this.currentinstitutionId) {
									let obj = {
										text: ele.name,
										value: ele.id
									}
									this.list.push(obj)
								}
							})
						} else {
							data.forEach(ele => {
								let obj = {
									text: ele.name,
									value: ele.id
								}
								this.list.push(obj)
							})
						}
					}
				})
			},
			getDaizhuanAllIntitutions() {
				getDaizhuanAllIntitutions().then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.id
							}
							this.list.push(obj)
						})

					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.searchSelect {
		width: 100%;
	}

	.searchSelect /deep/ .uni-select--disabled {
		background: transparent;
	}

	.searchSelect /deep/ .uni-select {
		font-size: 24rpx;
		height: 24px;
		border: none;
		min-height: 24px;
		padding: 0px;
	}

	.searchSelect /deep/ .uni-select__input-box {
		height: 24px;
	}

	.searchSelect /deep/ .uni-select--disabled .uni-select__input-text {
		color: #606266 !important;
	}
	.searchSelect /deep/  .uni-select__input-placeholder {
		color: #C0C4CC !important;
	}
</style>